import require from '@/utils/_require';
const API = {
  'SPUINFOLIST': '/admin/product',
  'ALLTRADEMARKLIST': '/admin/product/baseTrademark/getTrademarkList',
  'BASESALEATTRLIST': '/admin/product/baseSaleAttrList',
  'SPUIMAGELIST': '/admin/product/spuImageList',
  'SPUSALEATTRLIST': '/admin/product/spuSaleAttrList',
  'SAVESPUINFO': '/admin/product/saveSpuInfo',
  'UPDATESPUINFO': '/admin/product/updateSpuInfo',
  'DELETESPU': '/admin/product/deleteSpu',
  'SAVESKUINFO': '/admin/product/saveSkuInfo',
  'FINDBYSPUID': '/admin/product/findBySpuId',
}

// 获取spu信息列表
export const reqSpuInfoList = function (data) {
  const { page, limit, category3Id } = data
  return require({
    url: API.SPUINFOLIST + `/${page}/${limit}`,
    method: 'get',
    params: { category3Id }
  })
}

// 获取全部品牌列表
export const reqAllTrademarkList = function () {
  return require({
    url: API.ALLTRADEMARKLIST,
    method: 'get',
  })
}

// 获取指定spuId的图片列表
export const reqSpuImageList = function (spuId) {
  return require({
    url: API.SPUIMAGELIST + `/${spuId}`,
    method: 'get',
  })
}

// 获取全部spu销售属性
export const reqBaseSaleAttrList = function () {
  return require({
    url: API.BASESALEATTRLIST,
    method: 'get',
  })
}

// 获取指定spuId的全部的已有销售属性
export const reqSpuSaleAttrList = function (spuId) {
  return require({
    url: API.SPUSALEATTRLIST + `/${spuId}`,
    method: 'get',
  })
}

// 保存spu
export const reqSaveSpuInfo = function (data) {
  if (data.id) {
    // 有id，是更新操作
    return require({
      url: API.UPDATESPUINFO,
      method: 'post',
      data
    })
  }
  // 没有id，是保存操作
  return require({
    url: API.SAVESPUINFO,
    method: 'post',
    data
  })
}

// 删除spu
export const reqDeleteSpuInfo = function (spuId) {
  return require({
    url: API.DELETESPU + `/${spuId}`,
    method: 'delete'
  })
}

// 保存sku
export const reqSaveSkuInfo = function (data) {
  return require({
    url: API.SAVESKUINFO,
    method: 'post',
    data
  })
}

// 保存sku
export const reqSkuInfoBySpuId = function (spuId) {
  return require({
    url: API.FINDBYSPUID + `/${spuId}`,
    method: 'get',
  })
}







